<template>
  <AppHeader :title="moduleTypeName || title" :banAnimate="true" backgroundColor="#ffffff">
    <template #left>
      <img
        @click="onClickLeft"
        src="@/assets/images/icon-back-black.png"
        width="9"
        height="18"
      />
    </template>
    <template #right>
      <img
        @click="onTopClickRight"
        src="@/assets/images/listening/copy.png"
        width="18"
        height="18"
      />
    </template>
  </AppHeader>
  <div class="container">
    <div class="top">
      {{moduleTypeName || title}}
    </div>
    <div class="handleft" @click="onClickRight">
      <img
        src="@/assets/images/written/handleft.png"
        width="100"
        height="100"
      />
    </div>
  </div>
</template>

<script setup>
import AppHeader from "@/components/AppHeader.vue";
import { useRouter ,useRoute} from "vue-router";
import {onMounted, ref} from 'vue'
const router = useRouter();
const route = useRoute();
const moduleTypeName = ref('')
const title = ref('')
onMounted(()=>{
  title.value = JSON.parse(sessionStorage.getItem('resource')).title
  if( title.value.indexOf('读写') === -1){
    moduleTypeName.value = JSON.parse(sessionStorage.getItem('resource')).parts.find(item=>item.sid == route.query.sid).module_type_name
  }
})
const onClickLeft = () => {
  router.back();
};
const onTopClickRight = ()=>{
  router.push('/writtenTest/singleSubmit')
}
const onClickRight = () => { 
  var obj
  JSON.parse(sessionStorage.getItem('resource')).parts.forEach(item=>{
    if(item.sid === route.query.sid *1){
      obj = item.qtype
      if(item.children.length > 0){
        if(route.query.pId){
          item.children.forEach(child=>{
            if(child.sid === route.query.pId *1){
              obj = child.qtype
            }
          })
        }else{
          obj = item.children[0].qtype
        }
      }
    }else{
      if(item.children.length > 0){
        item.children.forEach(child=>{
          if(child.sid === route.query.sid *1){
            obj = child.qtype
          }
        })
      }else{
        if(item.sid === route.query.sid *1){
          obj = item.qtype
        }
      }
    }
  })
  if(obj===1){
    router.push({
      path: "/writtenTest/singleTest",
      query: { ...route.query },
    });
  }else if(obj === 5 || obj === 4 || obj === 6){//阅读理解
    router.push({
      path: "/writtenTest/readTest",
      query: { ...route.query },
    });
  }else if(obj === 3) {  //选择
    router.push({
      path: "/writtenTest/singleRightTest",
      query: { ...route.query },
    });
  }
  
}
</script>

<style lang="scss" scoped>
.container {
  height: 100%;
  background-color: #ffffff;
  padding-top: 44px;
  overflow-y: auto;
 .top{
  font-family: PingFangSC, PingFang SC;
font-weight: 500;
font-size: 16px;
color: #333333;
line-height: 22px;
text-align: left;
font-style: normal;
padding: 15px 10px;
 }
 .handleft{
  position: absolute;
  right: 14px;
  top: 50%;
  cursor: pointer;
 }
}
</style>
